package net.wanho.zaixian.course.controller;


import com.alibaba.fastjson.JSONObject;
import net.wanho.zaixian.course.service.CoursePicService;
import net.wanho.zaixian.pojo.course.CoursePic;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CoursePicController {

    @Resource
    private CoursePicService coursePicService;

    @PostMapping("/course/coursepic/add")
    public JSONObject addCoursePic(String courseId ,String pic){
        CoursePic coursePic = new CoursePic();
        coursePic.setCourseid(courseId);
        coursePic.setPic(pic);
        JSONObject jsonObject = new JSONObject();
        System.out.println(coursePic);

        try {
            coursePicService.addCoursePic(coursePic);
            jsonObject.put("success",true);
            return jsonObject;
        } catch (Exception e) {
            e.printStackTrace();
            jsonObject.put("success",false);
            return jsonObject;
        }

    }
   @GetMapping("/course/coursepic/list/{courseId}")
   public List<CoursePic> getCoursePic(@PathVariable(name="courseId") String courseId){
       List<CoursePic> coursePicByCourseId = coursePicService.findCoursePicByCourseId(courseId);
       System.out.println(coursePicByCourseId);
       return coursePicByCourseId;

   }

   @DeleteMapping("/course/coursepic/delete")
    public JSONObject deleteCoursePicByCourseId(String courseId){
       JSONObject jsonObject = new JSONObject();
       try {
           coursePicService.deleteCoursePicByCourseId(courseId);
           jsonObject.put("success",true);
           return jsonObject;
       } catch (Exception e) {
           e.printStackTrace();
           jsonObject.put("success",false);
           return jsonObject;
       }

   }

}
